<?php
$doNotAuth = true;
include_once(dirname(__FILE__)."/inc/common.php"); 

if(isset($_SESSION["userId"]) && $_SESSION["userId"]){
	header("location : index.php");
	exit;
}

if(isset($_POST["loginName"]) && isset($_POST["password"])){
	$userClass = new user_user();
	$result = array(
				'success' => false,
				'needLogin' => true,
				'message'=>"请先登录"
			);
	$defaultMsg = '用户名或密码错误！';
	try{
		if($userClass->login($_POST["loginName"], $_POST["password"])){
			$result = array(
				'success' => true
			);
		}else{
			$result = array(
				'success' => false,
				'msg' => $defaultMsg
			);
		}
	}catch(Exception $e){
		$result = array(
			'success' => false,
			'msg' => $e->getMessage()?$e->getMessage():$defaultMsg
		);
	}
	$jsonHandle = new ext_jsonHandle();
	$jsonHandle->jsonOut($result);
	exit();
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7">
    <meta http-equiv="”content-language”" content="zh-CN">
	<meta http-equiv="pragma" content="no-cache">	
	<meta http-equiv="expires" content="0">
	<link href="css/portal.css" rel="stylesheet" type="text/css">
	<script language="JavaScript" src="js/jquery-1.4.4.min.js" type="text/javascript"></script>
	<!-- 解决IE6下png显示问题-->
	<!--[if IE 6]> 
	<script src="js/DD_belatedPNG.js"></script> 
	<script> 
	DD_belatedPNG.fix('img,div,li'); 
	</script> 
	<![endif]--> 
    <script language="javascript">var ctx='.';</script>
<title>记账--登录</title>
</head>
<body>
<div id="login">

	      <div class="right">
	           <div id="login_h"></div>  
	           <div id="login_main">
					<div id="msgzone">
					</div>
	                <div id="loginFrmZone">
							<table>
							  <tbody><tr>
								  <td><label for="loginName">账&nbsp;&nbsp;&nbsp;&nbsp;号：</label></td>
								  <td><input class="input" type="text" name="loginName" id="loginName" maxlength="64" value="" notnull="true"></td>
							      <td></td>
							  </tr>
							  <tr>
								  <td><label for="password">密&nbsp;&nbsp;&nbsp;&nbsp;码：</label></td>
								  <td id="test123456"><input class="input" type="password" name="password" id="password" value="" maxlength="16"></td>
								  <td> &nbsp;&nbsp;</td>
							  </tr> 
							  
							   
							  
							  <tr height="40"><td></td>
							  <td>
								<!--<input name="rem" id="rem" type="checkbox" value="1" title="以后可自动登录.在网吧等公共电脑上,请勿选择使用此功能.">
								<label for="rem">记住我一个月</label>-->
							  </td>
							  </tr>
							  </tbody></table>
					</div>
	                
					
	                <div id="buttonzone">
	                        <input id="submitBtn" name="submitBtn" type="button" class="button_n" onclick="login();" value="登  录">
	                </div>
	                
					<div id="info_panel" style="margin-bottom: 30px;display:none;">
						
					    <ul id="u1">
					    	<li style="width:200px;margin-top: 10px;">演示账号/密码：demo/demo</li>					    
					    </ul>
					   
					    <ul id="u2"> 
					    <li><a href="http://www.caakee.com/passwordBeforeEmail.jsp">忘记密码</a></li> 
					    <li class="bar"></li> 

					    </ul>					    
					</div>						              
	           </div> 
	           <div id="login_f"></div>
	      </div>
	      </div>

</div>
<script language="JavaScript">
function login(){
	var loginName = $("#loginName").val().trim();
	var password = $("#password").val().trim();
	if(!loginName){
		showError("请输入用户名！");
		return false;
	}
	if(!password){
		showError("请输入密码！");
		return false;
	}
	$.ajax({
	   type: "POST",
	   url: "login.php",
	   data: {loginName:loginName, password:password},
	   dataType: "json",
	   success: function(body){
	   		if(body.success){
	   			window.location = "index.php";
	   		}else{
				showError(body.msg);
	   		}
	   },
	   error : function(){
			showError("登录失败！");
	   }
	});
}

function showError(msg){
	$("#msgzone").text(msg).show();
}
/*$(document).ready(function(){
	$(function() {
        $('input[placeholder]').each(function(i,o) {                
            jplaceholder($(o));
        });
    });
	//$('#loginName').focus();
	//回车时，默认是提交
	if(document.addEventListener){//如果是Firefox
		document.addEventListener("keypress",fireFoxHandler, true);
	}else{
		document.attachEvent("onkeypress",ieHandler);
	}
		
 }); */
</script></body></html>